	<template>
  <div class="app-container">
    <!--查询表单-->
    <el-form :inline="true" class="demo-form-inline">
      <el-form-item>
        <el-input v-model="teacherCondition.name" placeholder="讲师名" />
      </el-form-item>

      <el-form-item>
        <el-select
          v-model="teacherCondition.level"
          clearable
          placeholder="讲师头衔"
        >
          <el-option :value="1" label="高级讲师" />
          <el-option :value="2" label="首席讲师" />
        </el-select>
      </el-form-item>

      <el-form-item label="添加时间">
        <el-date-picker
          v-model="teacherCondition.beginTime"
          type="datetime"
          placeholder="选择开始时间"
          value-format="yyyy-MM-dd HH:mm:ss"
          default-time="00:00:00"
        />
      </el-form-item>
      <el-form-item>
        <el-date-picker
          v-model="teacherCondition.endTime"
          type="datetime"
          placeholder="选择截止时间"
          value-format="yyyy-MM-dd HH:mm:ss"
          default-time="00:00:00"
        />
      </el-form-item>

      <el-button
        type="primary"
        icon="el-icon-search"
        @click="paginationQueryEduTeacherByCondition()"
        >查询</el-button
      >
      <el-button type="default" @click="resetData()">清空</el-button>
    </el-form>
    <!-- 表格 -->
    <!--  v-loading="listLoading"属性：是否转圈圈 -->
    <el-table
      v-loading="listLoading"
      :data="teacherList"
      element-loading-text="数据加载中"
      border
      fit
      highlight-current-row
    >
      <el-table-column label="序号" width="70" align="center">
        <template slot-scope="scope">{{
          (pageNum - 1) * pageSize + scope.$index + 1
        }}</template>
      </el-table-column>

      <el-table-column prop="name" label="名称" width="80" />

      <el-table-column label="头衔" width="80">
        <template slot-scope="scope">{{
          scope.row.level === 1 ? "高级讲师" : "首席讲师"
        }}</template>
      </el-table-column>

      <el-table-column prop="intro" label="资历" />

      <el-table-column prop="gmtCreate" label="添加时间" width="160" />

      <el-table-column prop="sort" label="排序" width="60" />

      <el-table-column label="操作" width="200" align="center">
        <template slot-scope="scope">
          <router-link :to="'/teacher/edit/' + scope.row.id">
            <el-button type="primary" size="mini" icon="el-icon-edit"
              >修改</el-button
            >
          </router-link>
          <el-button
            type="danger"
            size="mini"
            icon="el-icon-delete"
            @click="deleteTeacherById(scope.row.id)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <el-pagination
      :current-page="pageNum"
      :page-size="pageSize"
      :total="total"
      style="padding: 30px 0; text-align: center"
      layout="total, prev, pager, next, jumper"
      @current-change="paginationQueryEduTeacherByCondition"
    />
  </div>
</template>
<script>
import teacher from "@/api/teacher";
export default {
  data() {
    return {
      //不转圈圈
      listLoading: false,
      teacherList: null,
      //没有定义 pageNum pageSize 页面中的序号会为NAN 因为js中没有定义的变量是undefined 进行运算就会NAN不是数字
      // (pageNum - 1) * pageSize + scope.$index + 1 下面两个变量是从上面这个地方粘贴过来的
      pageNum: 1,
      pageSize: 3,
      total: 0,
      teacherCondition: {},
    };
  },
  methods: {
    //分页按照条件查询所有的讲师
    paginationQueryEduTeacherByCondition(pageNumUI = 1) {
      //每到下一页 pageNumUI会加1 然后将pageNumUI作为参数传给paginationQueryEduTeacherByCondition
       this.pageNum = pageNumUI;
      teacher
        .paginationQueryEduTeacherByCondition(
          this.pageNum,
          this.pageSize,
          this.teacherCondition
        )
        //调用成功之后 有一个then()方法
        //response是服务器响应回来的数据
        .then((response) => {
          //小坑： 当时后台的数据能查出来 前端页面显示不出来 考虑 后台传过来的参数与前台的参数是否一致
          //当时 我后台response 的数据  return RetVal.success().data("total", total).data("records", records); 导致前台
          //拿不到response.data.teacherList  所以后台应为 return RetVal.success().data("total", total).data("teacherList", teacherList);
          this.teacherList = response.data.teacherList;
          this.total = response.data.total;
         
        });
    },
    //清空方法的实现
    resetData() {
      this.teacherCondition = {};
      this.paginationQueryEduTeacherByCondition();
    },
    //删除讲师前端页面的实现
    deleteTeacherById(teacherId) {
      this.$confirm("此操作将永久删除该文件, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          teacher.deleteEduTeacherById(teacherId).then((response) => {
            this.$message({
              message: "删除成功",
              type: "success",
            });
            this.paginationQueryEduTeacherByCondition();
          });
          this.$message({
            type: "success",
            message: "删除成功!",
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
  },
  created() {
    this.paginationQueryEduTeacherByCondition();
  },
};
</script>
    